package com.xsd.command;

/**
 * @Description:
 * @Author: zhoufuzong
 * @Created: 2021-03-06 15:51:36
 * @Version: 1.1.0
 */

public class Client {

    public static void main(String[] args) {
        // 使用命令设计模式 完成通过遥控器，对电灯的操作
        // 创建电灯的对象（接收者）
        LightReceiver lightReceiver = new LightReceiver();

        // 创建电灯相关的开关指令
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        // 需要一个遥控器
        RemoteController remoteController = new RemoteController();

        // 给我们的遥控器设置命令 比如 no =0; 是电灯的开和关
        remoteController.setCommand(0,lightOnCommand,lightOffCommand);
        System.out.println("--------按下灯的开按钮-----------");
        remoteController.onButtonWasPush(0);
        System.out.println("--------按下灯的关按钮-----------");
        remoteController.offButtonWasPush(0);
        System.out.println("--------按下撤销按钮-----------");
        remoteController.undoButtonWasPushed();

        System.out.println("******");
        TVReceiver tvReceiver = new TVReceiver();
        remoteController.setCommand(1,new TVOnCommand(tvReceiver),new TVOffCommand(tvReceiver));
        System.out.println("--------按下电视机的开按钮-----------");
        remoteController.onButtonWasPush(1);
        System.out.println("--------按下电视机的关按钮-----------");
        remoteController.offButtonWasPush(1);
        System.out.println("--------按下撤销按钮-----------");
        remoteController.undoButtonWasPushed();

    }

}
